<?php
namespace Home\Controller;
use Think\Controller;
class BaseController extends Controller {
    /**
     * Ajax方式返回数据到客户端
     * @access protected
     * @param mixed $data 要返回的数据
     * @param String $type AJAX返回数据格式
     * @param int $json_option 传递给json_encode的option参数
     * @return void
	 code 0成功 1无权限 1001失败
     */
    protected function ajaxReturn($data,$type='',$json_option=0) {
        $data = array(
            'data' => $data,
            'message' => $type,
            'success' => true,
        );
        parent::ajaxReturn($data);
    }

    protected function successreturn($data=null) {
        header('Content-Type:application/json; charset=utf-8');
		$returndata['code'] = 0;
		$returndata['data'] = $data; 
        exit(json_encode($returndata));
    }
	protected function errorreturn($data=null) {
        header('Content-Type:application/json; charset=utf-8');
		$returndata['code'] = 1001;
		$returndata['data'] = $data; 
        exit(json_encode($returndata));
    }
    protected function ajax($data,$count='',$type='',$code=0){
		$data = array(
		    'code'=>$code,
			'msg'=>$type,
			'count'=>$count,
			'data'=>$data,
		);
        parent::ajaxReturn($data);
	}
}